import React, { memo, useCallback, useRef, useState } from "react"

const App = memo(() => {
    const [count, setCount] = useState(0)

    // 通过useRef解决闭包陷阱
    const countRef = useRef()
    countRef.current = count

    const increment = useCallback(() => {
        setCount(countRef.current + 1)
    }, [])

    return (
        <div>
            <h2>Hello World</h2>
            <button onClick={(e) => setCount(count + 1)}>查看title的dom</button>
            <button onClick={increment}>count({count})</button>
        </div>
    )
})

export default App
